package com.wg.dome.repository;

import com.wg.db.cache.AbstractMultiCacheRepository;
import com.wg.dome.entity.user.EquipEntity;
import com.wg.common.lang.HashTable;

import java.io.Serializable;
import java.util.HashMap;

public class EquipRepository extends AbstractMultiCacheRepository<EquipEntity> {
    public EquipRepository() {
        super(EquipEntity.class);
    }


    /**
     * 数据转换为hashtable
     */
    public HashTable[] toHashTables(long playerId) {
        HashMap<Serializable, EquipEntity> map = getAllByGroupId(playerId, null);
        HashTable[] hashTables = new HashTable[map.size()];
        int i = 0;
        for (EquipEntity equipEntity : map.values()) {;
            hashTables[i++] = equipEntity.toHashTable();
        }
        return hashTables;
    }

    public EquipEntity getEntity(long playerId,long entityId){
        EquipEntity entity = get(playerId, equipEntity -> equipEntity.getId() == entityId);
        return entity;
    }
}
